package com.example.friend.controller.user;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.Result;
import com.example.common.core.enums.ResultCode;
import com.example.friend.domain.user.dto.UserDTO;
import com.example.friend.domain.user.dto.UserUpdateDTO;
import com.example.friend.service.user.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 23050
 * @version 1.0
 * @description: TODO
 * @date 2025/3/5 19:36
 */

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {



    @Resource
    private UserService userService;




    /**
     * @author 23050
     * @description:  获取验证码
     * @date: 2025/3/5 19:50
     * @param userDTO
     * @return java.lang.String
     */
    @PostMapping("/sendCode")
    public Result sentCode(@RequestBody UserDTO userDTO){
        String code = userService.sentCode(userDTO);
        return new Result(ResultCode.SUCCESS.getCode(),"验证码如下",code);
    }



    /**
     * @author 23050
     * @description:  登录注册功能接口
     * @date: 2025/3/5 19:56
     * @param userDTO
     * @return com.example.common.core.domain.Result
     */
    @PostMapping("/login")
    public Result login(@RequestBody UserDTO userDTO){

        return new Result<>(ResultCode.SUCCESS.getCode(),"登录成功",userService.login(userDTO));
    }


    /**
     * @author 23050
     * @description:  退出登录
     * @date: 2025/3/7 21:00
     * @param token
     * @return com.example.common.core.domain.Result
     */
    @DeleteMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String token){
        return userService.logout(token);
    }


    /**
     * @author 23050
     * @description:  从Redis中查询基本信息
     * @date: 2025/3/25 21:11
     * @param token
     * @return com.example.common.core.domain.Result
     */
    @GetMapping("/info")
    public Result info(@RequestHeader("Authorization") String token){
        return userService.info(token);
    }


    /**
     * @author 23050
     * @description:  查询用户基本信息
     * @date: 2025/3/25 21:13
     * @return com.example.common.core.domain.Result
     */
    @GetMapping("/detail")
    public Result detail(){
        return new Result(ResultCode.SUCCESS.getCode(),"用户信息",userService.detail());
    }


    /**
     * @author 23050
     * @description:  编辑用户信息
     * @date: 2025/3/26 21:28
     * @param userUpdateDTO
     * @return com.example.common.core.domain.Result
     */
    @PutMapping("edit")
    public Result edit(@RequestBody UserUpdateDTO userUpdateDTO){

        return new Result(ResultCode.SUCCESS.getCode(),"用户信息",userService.edit(userUpdateDTO));
    }







}
